package com.mine.distinctionteam.ui.good;

import android.os.Handler;

import com.mine.distinctionteam.base.IView;
import com.mine.distinctionteam.bean.goods.GoodsBean;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;


/**
 *
 */
public class GoodsPresenter implements GoodsContract.Presenter {
    private GoodsContract.View view;
    private GoodsContract.Modle modle;

    public GoodsPresenter(GoodsContract.View view){
        this.view=view;
        modle=new GoodsModle();
    }
    @Override
    public void getGoods(String id) {
        modle.getGoods(id, new Callback<GoodsBean>() {
            @Override
            public void onResponse(Call<GoodsBean> call, Response<GoodsBean> response) {
                final GoodsBean bean=response.body();
                Handler handler=new Handler();
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.getGoodsSucess(bean);
                    }
                });
            }

            @Override
            public void onFailure(Call<GoodsBean> call, Throwable t) {
                view.getGoodsFail("加载失败");
            }
        });
    }

    @Override
    public void detachView() {

    }

    @Override
    public void attachView(IView view) {

    }
}
